#include "HaarLikeDetector.h"
#include "XMLDetector.h"
#include <iostream>

using namespace std;
using namespace cv;

int main( int argc, char** argv )
{
	Mat lImg1 = imread("D:/Usagers/matre697/Data.nobkp/Test_affine/Essai_RAW_001.bmp");
	Mat lImg2 = imread("D:/Usagers/matre697/Data.nobkp/Test_affine/Essai_RAW_328.bmp");

	HaarLikeDetector* lDetectorFront = new HaarLikeDetector("front.xml","Front",1.0,1.05,7);
	HaarLikeDetector* lDetectorRear = new HaarLikeDetector("rear.xml","Rear",1.0,1.05,7);
	HaarLikeDetector* lDetectorLSide = new HaarLikeDetector("side.xml","LSide",1.0,1.1,4);
	HaarLikeDetector* lDetectorRSide = new HaarLikeDetector("side.xml","RSide",1.0,1.1,4,0,Size(),true);
	//XMLDetector* lDetectorFront = new XMLDetector("Front");
	//XMLDetector* lDetectorRear = new XMLDetector("Rear");
	//XMLDetector* lDetectorLSide = new XMLDetector("LSide");
	//XMLDetector* lDetectorRSide = new XMLDetector("RSide");

	cv::Point lPt1, lPt2; 

	vector<cv::Rect> lObjects1;
	vector<double> lConfidence1;
	cv::Scalar lColor1;	//BGRA
	lColor1.val[0]=0.0;
	lColor1.val[1]=0.0;
	lColor1.val[2]=255.0;
	lColor1.val[3]=0.0;
	int lNbObjects1 = lDetectorLSide->detectObjects(lObjects1,lConfidence1,lImg1);
	if(lNbObjects1 >= 0)
	{
		for (int i=0;i<lNbObjects1;i++)
		{
			cv::Rect lCarRect = lObjects1[i];
			lPt1.x = lCarRect.x;
			lPt2.x = (lCarRect.x+lCarRect.width);
			lPt1.y = lCarRect.y;
			lPt2.y = (lCarRect.y+lCarRect.height);
			cv::rectangle(lImg1,lPt1,lPt2,lColor1);
		}
		std::cout<<"Objects1"<<std::endl;
		for(int i=0;i<lNbObjects1;i++)
			std::cout<<"x:"<<lObjects1[i].x<<", y:"<<lObjects1[i].y<<", width:"<<lObjects1[i].width<<", height:"<<lObjects1[i].height<<", Confidence:"<<lConfidence1[i]<<std::endl;
		cv::imshow( "lImg1", lImg1 );
		cv::waitKey(0);
	}

	vector<cv::Rect> lObjects2;
	vector<double> lConfidence2;
	int lNbObjects2 = lDetectorFront->detectObjects(lObjects2,lConfidence2,lImg2);
	cv::Scalar lColor2;	//BGRA
	lColor2.val[0]=0.0;
	lColor2.val[1]=255.0;
	lColor2.val[2]=0.0;
	lColor2.val[3]=0.0;
	if(lNbObjects2 >= 0)
	{
		for (int i=0;i<lNbObjects2;i++)
		{
			CvRect lCarRect = lObjects2[i];
			lPt1.x = lCarRect.x;
			lPt2.x = (lCarRect.x+lCarRect.width);
			lPt1.y = lCarRect.y;
			lPt2.y = (lCarRect.y+lCarRect.height);
			cv::rectangle(lImg2,lPt1,lPt2,lColor2);
		}
		std::cout<<"Objects2"<<std::endl;
		for(int i=0;i<lNbObjects2;i++)
			std::cout<<"x:"<<lObjects2[i].x<<", y:"<<lObjects2[i].y<<", width:"<<lObjects2[i].width<<", height:"<<lObjects2[i].height<<", Confidence:"<<lConfidence2[i]<<std::endl;
		cv::imshow( "lImg2", lImg2 );
		cv::waitKey(0);
	}

	delete lDetectorFront;
	delete lDetectorLSide;

	return 0;
}
